package com.gopay.common.order.aop;

import java.io.IOException;

import org.aspectj.lang.JoinPoint;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;

import com.gopay.common.constants.logging.SendType;
import com.gopay.common.constants.logging.VoType;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import com.gopay.common.domain.logging.LogSender;
import com.gopay.common.hessian.ReceiveHessianKey;
import com.gopay.common.util.DateUtils;
import com.gopay.common.util.JsonUtils;

/**
 * 订单日志AOP通知
 * 
 * @LogAspect.java
 * @author yaobo
 * @2013-4-25 上午09:48:12 www.gopay.com.cn Inc.All rights reserved.
 */
public class MainOrderLogAspect extends AbstractOrderAspect {

    @Override
    public String buildData(JoinPoint jp) {
        CpsGenMainOrder order = (CpsGenMainOrder) jp.getArgs()[0];

        String snapshot = "";
        try {
            snapshot = JsonUtils.toJson(order);
        } catch (JsonGenerationException e1) {
            e1.printStackTrace();
        } catch (JsonMappingException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        LogSender sender = new LogSender();
        sender.setTargetId(order.getGopayOrderId());
        sender.setFrom(from);
        sender.setServiceName(getProcessServiceName());
        sender.setFromTime(DateUtils.getCurrDate());
        sender.setType(SendType.LOG.value + VoType.ORDER.value);
        sender.setData(snapshot);
        sender.setTkey(ReceiveHessianKey.getInstance());

        String data = "";

        try {
            data = JsonUtils.toJson(sender);
        } catch (JsonGenerationException e) {
            e.printStackTrace();
        } catch (JsonMappingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return data;
    }

}
